﻿using App.Common;
using QxFramework.Core;
using QxFramework.Utilities;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CardManager : MonoSingleton<CardManager>
{
    public bool banHint = false;

    [HideInInspector]
    public List<Card> _activeCards;

    [HideInInspector]
    public List<Card> _usedCards;

    public Transform _content;

    //生成新卡组
    public void InitCards()
    {
        _activeCards = new List<Card>();

        //删除所有卡片
        for (int i= 0;i < _content.childCount; i++)
        {
            GameObject.Destroy(_content.GetChild(i).gameObject);
        }

        Debug.Log("1");
        for (int i = 1; i <= Data.Instance.cardNum[Data.Instance.nowLevel - 1]; i++)
        {
            string path = "Prefabs/Levels/Level" + Data.Instance.nowLevel + "/Cards/Card" + i.ToString();
            Transform temp = Instantiate(Resources.Load<GameObject>(path)).transform;
            //temp.SetParent(GameObject.Find("Canvas").transform);
            temp.SetParent(_content);
            temp.localPosition = Vector3.zero;
            temp.localRotation = Quaternion.identity;
            temp.localScale = Vector3.one;/**/
            _activeCards.Add(temp.GetComponent<Card>());
        }


        _usedCards = new List<Card>();
    }

    public void UpdateCards(CardObject usedCard)
    {
        if (usedCard != null)
        {
            if (_activeCards.Contains(usedCard._bindCard)) 
            {
                _usedCards.Add(usedCard._bindCard);
                _activeCards.Remove(usedCard._bindCard);
                Destroy(usedCard._bindCard.gameObject);
            }
        }
        if (_activeCards.Count == 0)
        {
            if (!GameObject.Find("Map").GetComponent<LightCheck>().StartCheck(false))
            {
                Data.Instance.EndTheGame();
            }
        }
    }
}
